/* Kanvas Paint and Drawing Tool.
 * Copyright (C) 2011 Darryl Wallace
 * wallacdj@gmail.com / darryl@wallynet.ca
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*!
  @file ITool.h
  @author Darryl Wallace
  @date 2011
  @brief This file defines the common interface to all tools.
  */
#ifndef ITOOL_H
#define ITOOL_H

#include <QtGui>

class LayerItem;

/**
  \class ITool
  \brief This class is a base interface class for all tools.

  For tools that are drawing (especially shapes), they should be sub-class QGraphicsItem as well.
  See the code for the RectangleTool and use it as an example.

  \sa RectangleTool
  */
class ITool
{
public:

    /// Defines the type of tool.
    enum ToolType{
        Undefined = -1, /*!< Undefined tool*/
        Drawing = 0,    /*!< Tool used for drawing */
        Eraser = 1,     /*!< Tool used for erasing */
        Selection = 2   /*!< Tool used for eslections */
    };

    /// Constructor
    /*!
      \param parentLayer A Layer object will be the parent of the tool.  This is a QGraphicsItem subclass.
      */
    ITool(LayerItem *parentLayer=NULL) {};
    virtual ~ITool() {};

    /// Return the tool type.
    virtual ToolType toolType() const = 0;
    /// Sets the primary color for the tool.
    /*!
      This method would be used for drawing tools only.
      */
    virtual void setPrimaryColor(const QColor &) const = 0;
    /// Sets the secondary color.
    /*!
      This method would be used for drawing tools only.
      */
    virtual void setSecondaryColor(const QColor &)const = 0;

    /// Paint method
    /*!
      This is the expected paint method of a QGraphicsItem.
      */
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) = 0;

    /// Handle the mouse press event on the scene.
    /*!
      Call e->scenePos() to get the position of the event.
      \param e Mouse event on the scene.
      */
    virtual void handleMousePressEvent(const QGraphicsSceneMouseEvent *e) = 0;

    /// Handle the mouse move event on the scene.
    /*!
      Call e->scenePos() to get the position of the event.
      \param e Mouse event on the scene.
      */
    virtual void handleMouseMoveEvent(const QGraphicsSceneMouseEvent *e) = 0;

    /// Handle the mouse release event on the scene.
    /*!
      Call e->scenePos() to get the position of the event.
      \param e Mouse event on the scene.
      */
    virtual void handleMouseReleaseEvent(const QGraphicsSceneMouseEvent *e) = 0;

    /// Return the bounding rect of where this tool has operated
    /*!
      Depending on the tool, it may be necessary to return the bounding rect
      of where the tool has been working.  It is necessary for invalidating the region
      on the scene required for updating.
      \return The bounding rect.
      */
    virtual QRectF boundingRect() const = 0;

    /// Return the list of widgets to be shown on the toolbar.
    /*!
      Because we want to have custom options for each tool, you must
      create the list of widgets to be displayed on the tool bar.

      The tool bar will parent the items and they should be cleaned up automatically.
      \return List of the widgets that are to be displayed.
      */
    virtual QList<QWidget *> toolbarWidgets() const = 0;

    /// Return the tool cursor.
    /*!
      A tool may require a custom icon for the mouse cursor.
      If you only require the standard cross hair cursor
      then do not reimplement this method.

      \return QCursor for the graphics scene.
      */
    virtual QCursor mouseCursor() const {return QCursor(Qt::CrossCursor);}
};

#endif // ITOOL_H
